const { AsyncSeriesHook } = require('tapable')
// call   callAsync promise
class Lesson {
  constructor() {
    this.index = 0
    this.hooks = {
      arch: new AsyncSeriesHook(['name']),
    }
  }

  tap() {
    // 注册监听函数
    this.hooks.arch.tapAsync('node', (name, cb) => {
      setTimeout(() => {
        console.log('node', name)
        cb(null, 'result')
      }, 1000)
    })
    this.hooks.arch.tapAsync('react', (data, cb) => {
      setTimeout(() => {
        console.log('react', data)
        cb()
      }, 1000)
    })
  }

  start() {
    this.hooks.arch.callAsync('mjx', function () {
      console.log('end')
    })
  }
}

const l = new Lesson()
l.tap() // 注册这两个事件
l.start() // 启动钩子
